<template>
  <div class="container">
    <van-cell-group>
      <van-field v-model="channelNo" label="channelNo" placeholder="渠道号" />
      <van-field v-model="aac002" label="aac002" placeholder="身份证号" />
      <van-field v-model="aac003" label="aac003" placeholder="姓名" />
      <van-field
        v-model="ggfwPassword"
        label="password"
        placeholder="公共服务密码"
        type="password"
      />
      <van-field
        v-model="url"
        label="url"
        placeholder="申领地址"
        rows="5"
        type="textarea"
      />
    </van-cell-group>
    <g-button @click="applySSC">申领电子社保卡</g-button>
  </div>
</template>

<script>
import Button from "@/components/common/button/Button.vue";
import config from "./config";
import {getSSCApplyInfo, getSSCSign} from "../../apis/test";

export default {
  name: "TestApply",
  components: {
    GButton: Button
  },
  data() {
    return {
      channelNo: config.channelNo,
      aac002: config.aac002,
      aac003: config.aac003,
      aab301: config.aab301,
      ggfwPassword: config.ggfwPassword,
      sign: "",
      urlParam: ""
    };
  },
  created() {
    document.title = "申领电子社保卡";
    this.getSSCTestSigns();
  },
  computed: {
    url() {
      // return `${config.sscServer}/main?channelNo=${this.channelNo}&aac002=${this.aac002}&aac003=${this.aac003}&aab301=${this.aab301}&isWeb=1`;
      return `${config.sscServer}/${this.urlParam}?channelNo=${this.channelNo}&${this.sign}`;
    }
  },
  methods: {
    getSSCTestSigns() {
      this.$store.dispatch("getSSCTestSign", {}).then(res => {
        this.urlParam = res.signNo ? "indep/cardInfo" : "main";
        this.sign = res.sign;
      });
    },
    async apply(params, data) {
      let result = await getSSCSign(params);
      this.sign = result.data;
      this.urlParam = data;
    },
    applySSC() {
      setTimeout(() => {
        location.href = this.url;
      }, 1000);
    }
  }
};
</script>

<style lang="less" scoped></style>
